Skip to content

Conversation

@landonxjames
Copy link
Contributor

Issue #, if available:

Description of changes:

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@landonxjames landonxjames marked this pull request as ready for review October 8, 2025 18:10
@landonxjames landonxjames requested a review from a team as a code owner October 8, 2025 18:10
pub(crate) struct TokenBucketMetrics {
max_tokens: u64,
available_tokens: UpDownCounter,
token_wait_time: Histogram,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this will be meaningful or not given permit requests come with different token amounts requested.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if tracking percentage of available tokens over time or something would be more useful?

// NOTE: tokio semaphore is fair, permits are given out in the order requested
semaphore: Arc<Semaphore>,
mode: ConcurrencyMode,
tb_metrics: Arc<TokenBucketMetrics>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm kind of wondering whether token bucket metrics provide value at this point in time. 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am also not sure, but will probably leave them in place until I can actually run some benchmarks and test all of this on some real use cases. Can remove if we find it not necessary after that testing.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok maybe add a comment or something to that effect

Remove permit acquisition/release tracking and simplify inflight
request monitoring with consistent counter types.
pub(crate) struct Scheduler {
token_bucket: TokenBucket,
pub(crate) metrics: SchedulerMetrics,
pub(crate) metrics: Arc<SchedulerMetrics>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: will this end up double-Arc ing? Individual fields of SchedulerMetrics seem to have their types backed by Arc already, e.g. Histogram, Gauge?

// High water mark for inflight tasks
max_inflight: IncreasingCounter,
// Count of failed permit acquisitions
permit_acquisition_failures: IncreasingCounter,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure we need this at this stage

// NOTE: tokio semaphore is fair, permits are given out in the order requested
semaphore: Arc<Semaphore>,
mode: ConcurrencyMode,
tb_metrics: Arc<TokenBucketMetrics>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok maybe add a comment or something to that effect

fn new(
sem: PollSemaphore,
tokens: u32,
tb_metrics: Arc<TokenBucketMetrics>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this feels off/wrong to need all these parameters for this future but I get why it's done. Wondering if there isn't a cleaner approach though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants